﻿<UserControl x:Class="VmroleAuthor.Views.ViewDefOptionParameterTypeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vw="clr-namespace:VmroleAuthor.Views"
             mc:Ignorable="d" 
             d:DesignWidth="900">
    <UserControl.Resources>
        <Style x:Key="MyButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Margin" Value="4" />
            <Setter Property="Height" Value="28" />
            <Setter Property="BorderThickness" Value="0"></Setter>
        </Style>
        <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
        </Style>      
        <vw:BoolToStringConverter x:Key="BoolToStringConverter" />
    </UserControl.Resources>
    <DockPanel  LastChildFill="True">
        <Grid DockPanel.Dock="Top"  VerticalAlignment="Top" ShowGridLines="False">
            <Grid.RowDefinitions>
                <RowDefinition Height="6" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition MinHeight="30" />
                <RowDefinition Height="Auto" />
                <RowDefinition MinHeight="30" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="6"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="6"/>
            </Grid.ColumnDefinitions>

            <!-- Delete this / Move this up/down -->
            <StackPanel Grid.Row="1"  Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Style="{StaticResource MyButtonStyle}"  Name="btnMoveUp"  Command="{Binding MoveViewDefParameterUpCommand}">
                    <Image Source="../Img/Arrow_Up.png" />
                </Button>
                <Button Style="{StaticResource MyButtonStyle}"  Name="btnMoveDown"  Command="{Binding MoveViewDefParameterDownCommand}">
                    <Image Source="../Img/Arrow_Down.png" />
                </Button>
                <Button Style="{StaticResource MyButtonStyle}"  Name="btnDelete"  Command="{Binding RemoveViewDefParameterCommand}">
                    <Image Source="../Img/deletered.png" />
                </Button>
            </StackPanel>
            <!-- Delete this -->

            <!-- Name -->
            <Label Grid.Row="2" Grid.Column ="0" >Name</Label>
            <TextBox x:Name="ViewDefParamName" Grid.Row="2" Grid.Column="2" Text="{Binding Name, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
            <ContentPresenter Grid.Row="3" Grid.Column="3" Content="{Binding ElementName=ViewDefParamName, Path=(Validation.Errors).CurrentItem}" />

            <!-- Type -->
            <Label Grid.Row="4" Grid.Column="0" >Type</Label>
            <ComboBox x:Name="ParamTypeCmbBox" Grid.Row="4"  Grid.Column="2" IsEditable="True"  IsReadOnly="True" ItemsSource="{Binding  AvailableParameterTypes}" SelectedItem="{Binding Type}" Text="{Binding Type, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}"/>
            <ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=ParamTypeCmbBox, Path=(Validation.Errors).CurrentItem}" />

        </Grid>
        <Expander DockPanel.Dock="Bottom"  Header="Details"  IsExpanded="{Binding IsExpanded}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="6" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="6"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="6"/>
                </Grid.ColumnDefinitions>

                <!-- Label -->
                <Label Grid.Row="1" Grid.Column ="0" >Label</Label>
                <ContentControl Grid.Row="1" Grid.Column="2" Content="{Binding Path=Label}" />

                <!-- DefaultValue -->
                <Label Grid.Row="2" Grid.Column ="0" >DefaultValue</Label>
                <ContentControl Grid.Row="2" Grid.Column="2" Content="{Binding Path=DefaultValue}" />

                <!-- Description -->
                <Label Grid.Row="3" Grid.Column ="0" >Description</Label>
                <ContentControl Grid.Row="3" Grid.Column="2" Content="{Binding Path=Description}" />

                <!--Configurable -->
                <Label Grid.Row="4" Grid.Column ="0" >Configurable</Label>
                <TextBox  x:Name ="Configurable" Grid.Row="4" Grid.Column="2"  Text="{Binding Path=Configurable, Converter={StaticResource BoolToStringConverter}}" />
                <ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=Configurable, Path=(Validation.Errors).CurrentItem}" />

                <!-- Options -->
                <Label  Grid.Row="6" Grid.Column="0" >Options</Label>
                <DataGrid  x:Name="Options" Grid.Row="6" Grid.Column="2" AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding Options, ValidatesOnExceptions=True}">
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>
                            <Style.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="BorderBrush" Value="Blue" />
                                    <Setter Property="BorderThickness" Value="2" />
                                    <Setter Property="Background" Value="LightBlue" />
                                    <Setter Property="Foreground" Value="Black" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Style.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="Background" Value="White" />
                                    <Setter Property="Foreground" Value="Black" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGrid.CellStyle>
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="Option Key" MinWidth="350">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Key, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Key, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />                                 
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="Option Value (Friendly description)" MinWidth="350">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding OptionValue.PropertyValue,  ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>                                                                       
                                    <ComboBox x:Name="OptionValue" IsEditable="True" 
                                      ItemsSource="{Binding  OptionValue.AvailableLocalizedPropertyValues}" 
                                      SelectedItem="{Binding OptionValue.SelectedPropertyValue}" 
                                      Text="{Binding OptionValue.PropertyValue, UpdateSourceTrigger=LostFocus, 
                                        Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                      />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
                <ContentPresenter Grid.Row="7" Grid.Column="2" Content="{Binding ElementName=Options, Path=(Validation.Errors).CurrentItem}" />

                <!-- Insert or Delete Rows using button -->
                <StackPanel Orientation = "Horizontal" HorizontalAlignment="Left" Grid.Row="8" Grid.Column="2" >
                    <Grid>
                        <Grid.RowDefinitions >
                            <RowDefinition Height="6" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="6" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Row="1" Grid.Column="0" Command="{Binding AddOptionCommand}" >
                            <StackPanel Orientation = "Horizontal">
                                <Image  Source="..\Img\addgreen.png" Width="20" Height="20" ></Image>
                                <TextBlock Margin="5,0,0,0">Insert</TextBlock>
                            </StackPanel>
                        </Button>
                        <Button Grid.Row="1" Grid.Column="2" Command="{Binding RemoveOptionCommand}" CommandParameter="{Binding ElementName=Options, Path=SelectedItem}">
                            <StackPanel Orientation = "Horizontal">
                                <Image  Source="..\Img\deletered.png" Width="20" Height="20"></Image>
                                <TextBlock Margin="5,0,0,0">Delete</TextBlock>
                            </StackPanel>
                        </Button>
                    </Grid>
                </StackPanel>                             

                <!--ValidationRequired -->
                <Label Grid.Row="9" Grid.Column ="0" >Required?</Label>
                <CheckBox x:Name ="ValidationRequired" Grid.Row="9" Grid.Column="2"   Style="{StaticResource ResourceKey=CheckBoxStyle}" IsChecked="{Binding ValidationRequired, Mode=TwoWay, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}"/>
                <ContentPresenter Grid.Row="10" Grid.Column="2" Content="{Binding ElementName=ValidationRequired, Path=(Validation.Errors).CurrentItem, UpdateSourceTrigger=PropertyChanged}" />

                <!-- ValidationMessageRequired -->
                <Label Grid.Row="11" Grid.Column ="0" >RequiredMessage</Label>
                <ContentControl Grid.Row="11" Grid.Column="2" Content="{Binding Path=ValidationMessageRequired}" />
            </Grid>
        </Expander>
    </DockPanel>  
</UserControl>
